package com.azkj.album.view.widgets.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.azkj.album.R;
import com.azkj.album.utils.DensityUtils;


/**
 * dexc :分享弹窗
 */
public class ShareBottomDialog {

    public static final class Builder {
        private Context mContext;
        private final View contentView;
        private final Dialog mDialog;
        private ItemClickListener mListener;
        private boolean isShowDownLoad;

        public Builder(Context context) {
            this.mContext = context;

            contentView = LayoutInflater.from(context).inflate(
                    R.layout.dialog_share_buttom, null);
            initView(contentView);
            // 定义Dialog布局和参数
            mDialog = new Dialog(context, R.style.ShareDialog);
            mDialog.setContentView(contentView);
            Window dialogWindow = mDialog.getWindow();
            dialogWindow.setGravity(Gravity.LEFT | Gravity.BOTTOM);
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.width = (int) (DensityUtils.getScreenWidth(context));
            lp.height = (int) ((int) (DensityUtils.getScreenHeight(context)) - DensityUtils.getStatusBarHeight(context));
            dialogWindow.setAttributes(lp);
        }


        public Builder setCallBack(ItemClickListener listener) {
            this.mListener = listener;
            return this;
        }

        public Builder setShowDownLoad(boolean isShow) {
            this.isShowDownLoad = isShow;
            contentView.findViewById(R.id.tv_download).setVisibility(isShowDownLoad ? View.VISIBLE : View.GONE);
            contentView.findViewById(R.id.v_download_line).setVisibility(isShowDownLoad ? View.VISIBLE : View.GONE);
            return this;
        }


        /**
         * 显示弹窗
         */
        public Builder show() {
            if (null != mDialog)
                mDialog.show();
            return this;
        }

        /**
         * 初始化布局
         *
         * @param view
         */
        private void initView(View view) {

            view.findViewById(R.id.tvCancel).setOnClickListener(v -> mDialog.dismiss());
            view.findViewById(R.id.tv_share_wx).setOnClickListener(v -> {
                if (mListener != null) mListener.onFriendClick();
                if (null != mDialog) mDialog.dismiss();
            });
            view.findViewById(R.id.tv_share_zone).setOnClickListener(v -> {
                if (mListener != null) mListener.onZoneClick();
                if (null != mDialog) mDialog.dismiss();
            });
            view.findViewById(R.id.tv_share_dy).setOnClickListener(v -> {
                if (mListener != null) mListener.onDyClick();
                if (null != mDialog) mDialog.dismiss();
            });
            view.findViewById(R.id.tv_download).setOnClickListener(v -> {
                if (mListener != null) mListener.onDownload();
                if (null != mDialog) mDialog.dismiss();
            });

        }

        public interface ItemClickListener {
            void onFriendClick();

            void onZoneClick();

            void onDyClick();

            void onDownload();
        }


    }
}
